| Server IP : 121.121.20.254 / Your IP : 216.73.216.202 Web Server : Microsoft-IIS/10.0 System : Windows NT WEB-SERVER 10.0 build 20348 (Windows Server 2022) AMD64 User : IUSR ( 0) PHP Version : 8.3.28 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Program Files/LibreOffice/help/en-US/text/sbasic/shared/ |
Upload File : |
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<base href="../../../../">
<noscript><meta http-equiv="refresh" content="0; URL=../../../../en-US/noscript.html"></noscript>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Replace Function</title>
<link rel="shortcut icon" href="media/navigation/favicon.ico">
<link type="text/css" href="normalize.css" rel="Stylesheet">
<link type="text/css" href="prism.css" rel="Stylesheet">
<link type="text/css" href="default.css" rel="Stylesheet">
<script type="text/javascript" src="polyfills.js"></script><script type="text/javascript" src="languages.js"></script><script type="text/javascript" src="en-US/langnames.js"></script><script type="text/javascript" src="flexsearch.debug.js"></script><script type="text/javascript" src="prism.js"></script><script type="text/javascript" src="help2.js" defer></script><script type="text/javascript" src="a11y-toggle.js" defer></script><script type="text/javascript" src="paginathing.js" defer></script><script type="text/javascript" src="en-US/bookmarks.js" defer></script><script type="text/javascript" src="en-US/contents.js" defer></script><script type="text/javascript" src="help.js" defer></script><meta name="viewport" content="width=device-width,initial-scale=1">
</head>
<body>
<header id="TopLeftHeader"><a class="symbol" href="en-US/text/shared/05/new_help.html"><div></div></a><a class="logo" href="en-US/text/shared/05/new_help.html"><p dir="auto">LibreOffice 24.2 Help</p></a><div class="dropdowns"><div class="modules">
<button type="button" data-a11y-toggle="modules-nav" id="modules" aria-haspopup="true" aria-expanded="false" aria-controls="modules-nav">Module</button><nav id="modules-nav" hidden=""></nav>
</div></div></header><aside class="leftside"><input id="accordion-1" name="accordion-menu" type="checkbox"><label for="accordion-1" dir="auto">Contents</label><div id="Contents" class="contents-treeview"></div></aside><div id="SearchFrame"><div id="Bookmarks">
<input id="search-bar" type="search" class="search" placeholder="Search in bookmarks for chosen module" dir="auto"><div class="nav-container" tabindex="0"><nav class="index" dir="auto"></nav></div>
</div></div>
<div id="DisplayArea" itemprop="softwareHelp" itemscope="true" itemtype="http://schema.org/SoftwareApplication">
<a name="replace"></a>
<a name="bm_id721552551162491"></a>
<meta itemprop="keywords" content="Replace function">
<h1 id="hd_id781552551013521" dir="auto">Replace Function</h1>
<p id="par_id291552551013522" class="paragraph" dir="auto">Replaces some string by another.</p>
<div class="embedded">
<a name="functsyntax"></a>
<h3 id="hd_id061420171139089682" dir="auto">Syntax:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
Replace (Expression As String, Find As String, Replace As String [, Start = 1 [, Count = -1 [, Compare = True]]]) As String
</code></pre></div>
<div class="embedded">
<a name="kwargs"></a>
<p id="par_id591622730284162" class="paragraph" dir="auto">When needing to pass less parameters, use keywords arguments. Passing values for fewer parameters by position requires to supply values for all parameters before them, optional or not. This ensures that the values are in the correct positions. If you pass the parameters by name - using keyword arguments - you may omit all other intermediate arguments.</p>
</div>
<div class="embedded">
<a name="functvalue"></a>
<h3 id="hd_id061420171139087480" dir="auto">Return value:</h3>
</div>
<p id="par_id911552552252024" class="paragraph" dir="auto">String</p>
<div class="embedded">
<a name="functparameters"></a>
<h3 id="hd_id061420171139084157" dir="auto">Parameters:</h3>
</div>
<p id="par_id721552552263062" class="paragraph" dir="auto"><span class="emph">Expression:</span> Any string expression that you want to modify.</p>
<p id="par_id901552552269836" class="paragraph" dir="auto"><span class="emph">Find:</span> Any string expression that shall be searched for.</p>
<p id="par_id791552552275383" class="paragraph" dir="auto"><span class="emph">Replace:</span> Any string expression that shall replace the found search string.</p>
<p id="par_id111552552283060" class="paragraph" dir="auto"><span class="emph">Start:</span> Optional numeric expression that indicates the character position where the search starts and also the start of the substring to be returned.</p>
<p id="par_id921552552289833" class="paragraph" dir="auto"><span class="emph">Count:</span> Optional maximum number of times the replace shall be performed. When set to -1, all possible replacements are performed.</p>
<p id="par_id891552552302894" class="paragraph" dir="auto"><span class="emph">Compare:</span> Optional boolean expression that defines the type of comparison. The value of this parameter can be <span class="literal">True</span> or <span class="literal">False</span>. The default value of <span class="literal">True</span> specifies a text comparison that is not case-sensitive. The value of <span class="literal">False</span> specifies a binary comparison that is case-sensitive. You can as well use 0 instead of <span class="literal">False</span> or 1 instead of <span class="literal">True</span>.</p>
<div class="embedded">
<a name="errorcode"></a>
<h3 id="hd_id3152869" dir="auto">Error codes:</h3>
</div>
<div class="embedded"><p class="embedded" dir="auto">5 Invalid procedure call</p></div>
<div class="embedded">
<a name="functexample"></a>
<h3 id="hd_id061420171139088233" dir="auto">Example:</h3>
</div>
<div class="bascode" itemscope="true" itemtype="http://schema.org/SoftwareSourceCode" itemprop="codeSampleType" content="snippet" data-tooltip="Click on text to copy to clipboard"><pre dir="auto"><code class="language-visual-basic line-numbers">
MsgBox Replace ("aBbcnnbnn", "b", "$", 1, 1, False) 'returns "aB$cnnbnn"
REM meaning: "b" should be replaced, but
REM * only when lowercase (compare=False), hence second occurrence of "b"
REM * only first (respecting case) occurrence (count=1)
MsgBox Replace ("ABCDEFGHI", "E", "*", 4)
REM returns D*FGHI because the search starts at position 4, which is also the start of the returned string.
MsgBox Replace("aBbcnnbnn", "b", "$£", compare:=False) 'returns "aB$£cnn$£nn"
REM Replace all (count = -1) "b" with "$£" respecting casing (compare=False) starting from first letter (start=1)
</code></pre></div>
<a name="relatedtopics"></a><div class="relatedtopics">
<p class="related" itemprop="mentions" dir="auto"><a name="related"></a><span class="emph">Related Topics</span>
</p>
<div class="relatedbody" itemprop="mentions">
<p id="par_id161599082457466" class="paragraph" dir="auto"><a target="_top" href="en-US/text/sbasic/shared/03120300.html">String functions</a></p>
<p id="par_id361623159933508" class="paragraph" dir="auto"><a target="_top" href="en-US/text/sbasic/shared/03/sf_string.html"><span class="literal">ScriptForge</span>.<span class="literal">String</span> service</a></p>
</div>
</div>
</div>
<div id="DonationFrame"></div>
<footer><div id="DEBUG" class="debug">
<h3 class="bug">Help content debug info:</h3>
<p dir="auto">This page is: <a href="https://opengrok.libreoffice.org/xref/help/source/text/sbasic/shared/replace.xhp" target="_blank">/text/sbasic/shared/replace.xhp</a></p>
<p dir="auto">Title is: Replace Function</p>
<p id="bm_module" dir="auto"></p>
<p id="bm_system" dir="auto"></p>
<p id="bm_HID" dir="auto"></p>
</div></footer>
</body>
</html>